package com.lvan.service;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import javax.servlet.ServletContext;

import org.springframework.web.context.ServletContextAware;

/**
 * @author Stern He<br>
 * 2013-9-16<br>
 * @version 1.0.0.0 
 */
public class LoadSysInfo implements ServletContextAware{
    private ServletContext context;
   
    private Map<String, Object> sysInfo;
    private String config_path;
    
    public void init() {
        sysInfo = new HashMap<String, Object>();
        String path=this.getClass().getResource("/").getPath().replaceAll("%20", " ");
        path = path.substring(0, path.indexOf("WEB-INF")) + config_path; 
        Properties p = new Properties();
        try {
            p.load(new FileInputStream(path));
            Set<Object> set = p.keySet();
            for(Object o : set) {
                sysInfo.put(o.toString(), p.getProperty(o.toString()));
            }
            context.setAttribute("sys", sysInfo);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public String getConfig_path() {
        return config_path;
    }
    public void setConfig_path(String config_path) {
        this.config_path = config_path;
    }
    @Override
    public void setServletContext(ServletContext arg0) {
        context = arg0;
    }
    
}
